/**
 *  Copyright 2009 Henning Teek, Ingo Renner
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *  http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. 
 */

package com.googlecode.chigsquickstart.web.plugin;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import com.googlecode.chigsquickstart.web.helloworld.HelloWorldTile;

import brix.Brix;
import brix.Plugin;
import brix.jcr.api.JcrSession;
import brix.plugin.site.page.tile.Tile;
import brix.registry.ExtensionPointRegistry;
import brix.web.tab.AbstractWorkspaceTab;
import brix.web.tab.IBrixTab;
import brix.workspace.Workspace;

/**
 * @author Ingo Renner
 * @author Henning Teek
 */
public class QuickstartPlugin implements Plugin {

    public QuickstartPlugin(Brix brix) {
        final ExtensionPointRegistry registry = brix.getConfig().getRegistry();
        registry.register(Tile.POINT, new HelloWorldTile());
    }
    
	@Override
	public String getId() {
		return getClass().getName();
	}

	@Override
	public String getUserVisibleName(Workspace workspace, boolean isFrontend) {
		return null;
	}

	@Override
	public List<Workspace> getWorkspaces(Workspace currentWorkspace, boolean isFrontend) {
		return null;
	}

	@Override
	public void initWorkspace(Workspace workspace, JcrSession workspaceSession) {
	}

	@Override
	public boolean isPluginWorkspace(Workspace workspace) {
		return false;
	}

	@Override
	public List<IBrixTab> newTabs(IModel<Workspace> workspaceModel) {
        IBrixTab tabs[] = new IBrixTab[]{new Tab(new Model<String>("Quickstart"), workspaceModel)};
        return Arrays.asList(tabs);
	}

    static class Tab extends AbstractWorkspaceTab {
        public Tab(IModel<String> title, IModel<Workspace> workspaceModel) {
            super(title, workspaceModel, 99);
        }

        @Override
        public Panel newPanel(String panelId, IModel<Workspace> workspaceModel) {
            return new QuickstartPanel(panelId, workspaceModel);
        }
    }	
}
